@layout("/common/_container.html"){
<div class="ibox float-e-margins">
    <div class="ibox-content">
        <form class="form-horizontal">
            <input id="phaseId" type="hidden"  value="${ptClass.phaseId}">
            <input id="schoolYear" type="hidden" name="schoolYear" value="${ptClass.schoolYear}">
            <input id="gradeId" type="hidden" value="${ptClass.gradeId}">
            <input id="id" type="hidden" name="classId" value="${ptClass.id}">
            <input type="hidden" id="orgId" name="orgId" value="${ptClass.orgId}" >
            <input type="hidden" id="teacherMap" value='${subjectTeacherMap}'>
            <div class="row">
                <div class="col-sm-12 ">

                    <#input id="name" name="班级名称" value="${ptClass.name}" underline="true" disabled="disabled"/>
                    @for(subject in subjectList){
                    <div class="form-group">
                        <label class="col-sm-3 control-label" >${subject.name}</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="classUserList[${subjectLP.index }].subjectId" value="${subject.id}" type="hidden"/>
                        </div>
                        <select id ="queryDevice-${subject.id}" name="classUserList[${subjectLP.index }].userId" class="selectpicker col-sm-9 "  value="${subject.id}" style="float: right;color: white" data-live-search="true" onclick="initOrglist(this)">
                        </select>
                    </div>
                @}
</div>
</div>
        </form>

<div class="row btn-group-m-t">
    <div class="col-sm-10" style="text-align: center">
        <#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="PtClassInfoDlg.editClassTeacher()"/>
        <#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="PtClassInfoDlg.close()"/>
    </div>
</div>
</div>

</div>
</div>
<script src="${ctxPath}/static/modular/system/ptClass/ptClass_info.js"></script>
<script>
    $(function() {
        $(".selectpicker").selectpicker({
            noneSelectedText: '请点击显示' //默认显示内容  
        });


    });

    //绑定bootstrap-select事件
    $(".selectpicker").on('shown.bs.select',function(e){
        initOrglist(this.id,$(this).attr("value"));
        var id=this.id;

        //为input绑定事件
        $("#"+id).prev().find("input").keyup(function(){
            //为input增加id属性，见下方截图
            $("#queryDevice").prev().find("input").attr('id',"userName");

        })
    });

    function initOrglist(obj,subjectId){
        teacherMap=JSON.parse($("#teacherMap").val());
        var id=obj;
        var orgId=$("#orgId").val();
        var phaseId=$("#phaseId").val();
        var subjectId=subjectId;
        var schoolYear=$("#schoolYear").val();
        var gradeId=$("#gradeId").val();
        $.ajax({
            type: "post",
            url:Feng.ctxPath+'/ptClass/suggestTeacherList',
            data:{'orgId':orgId,"phaseId":phaseId,"subjectId":subjectId,"schoolYear":schoolYear,"gradeId":gradeId},
            async:false,
            dataType: "json",
            success: function(data){
                var teacherList = data;
                if (teacherList.length>0) {
                    var teacherNameStr ='<option value=""></option>';
                    for (var i = 0; i < teacherList.length; i++) {
                        teacherNameStr += "<option value='" +teacherList[i].userId + "' ";
                        if (teacherMap[subjectId]!=null){
                        if(teacherMap[subjectId].id===teacherList[i].userId){
                            teacherNameStr += " selected='selected' ";
                        }
                        }
                        teacherNameStr += ">" + teacherList[i].userName + "</option>";
                    }
                    $("#"+id).html(teacherNameStr);
                    //必须加，刷新select
                    $("#"+id).selectpicker('refresh');
                }
            }
        });
    }
</script>
@}
